package com.study.d012Components.dialog;

import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.TextInputDialog;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.layout.AnchorPane;

/** 带输入框的弹出框
*@description
*@author xtayhame
*date 2020年3月14日
*version
*since v1.0
*/
public class TextInputDialogMain extends Application{
	String result=null;

	public static void main(String[] args) {
		launch(args);
	}
	public void start(javafx.stage.Stage stage) throws Exception {
		AnchorPane anchorPane = new AnchorPane();

		Button button  = new Button("弹窗");

		anchorPane.getChildren().add(button);
		AnchorPane.setTopAnchor(button, 30.0);
		AnchorPane.setLeftAnchor(button, 30.0);

		stage.setScene(new Scene(anchorPane,400,300));
		stage.show();

		button.setOnAction(new EventHandler<ActionEvent>() {

			@Override
			public void handle(ActionEvent event) {
				//信息确认框
				TextInputDialog in = new TextInputDialog("请输入值");



				Button ok=(Button)in.getDialogPane().lookupButton(ButtonType.OK);

				in.show();

				in.getEditor().textProperty().addListener(new ChangeListener<String>() {
					@Override
					public void changed(ObservableValue<? extends String> observable, String oldValue,
							String newValue) {
						System.out.println(""+ newValue);
						result = newValue;
					}
				});

				ok.setOnAction(new EventHandler<ActionEvent>() {
					@Override
					public void handle(ActionEvent event) {
						if(result !=null){
							System.out.println("你输入的是:" + result);
						}
					}
				});

			}

		});

	}
}

